#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
ll n, t, p; //n道题 , 比赛持续t分钟 , 本次比赛错误提交罚分
ll sa[20];//分数
ll sb[20];
ll sx[20];
ll sy[20];
ll sc[20];
ll h[20];//时间
ll sum = 0;
bool st[20];
void dfs(ll time, ll cur)
{
    sum = max(sum, cur);
    for(int i = 1; i <= n; i++)
    {
        if(!st[i])
        {
            if(time + h[i] <= t)
            {
                st[i] = true;
                dfs(time + h[i], cur + max(sc[i], sa[i] - (time + sx[i])*sb[i] - (sy[i]*p)));
                st[i] = false;

            }
        }
    }
}
int main()
{
    close();
    cin >> n >> t >> p;

    for( int i = 1; i <= n; i++)
    {
        ll a, b, c, x, y; //a为满分 b为时间系数 , c为保底分
        cin >> a >> b >> c >> x >> y;

        //ll cur = max(c, a - (x * b) - (y * p));
        sa[i] = a;
        sb[i] = b;
        sc[i] = c;
        sx[i] = x;
        sy[i] = y;
        h[i] = x;
    }

    dfs(0, 0);

    cout << sum << '\n';
    return 0;
}